package controlers;

import java.util.HashMap;
import java.util.Map;

import models.Usuario;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class CadastroControler extends ActionSupport 
{
	String username, password, adress, age, nome;
	Map<String, Object> aplication;

	@SuppressWarnings("unchecked")
	@Override
	public String execute()
	{
		aplication = ActionContext.getContext().getApplication();
		Map<String,Usuario> cadastro = (HashMap<String,Usuario>)aplication.get("cad");
		if(cadastro == null)
		{
			cadastro = new HashMap<String,Usuario>();
			aplication.put("cad", cadastro);
		}
		Usuario newUser = new Usuario();
		newUser.setAddress(adress);
		newUser.setLogin(username);
		newUser.setSenha(password);
		newUser.setIdade(Integer.valueOf(age));
		newUser.setNome(nome);
		if(!cadastro.containsKey(username)) 
		{
			cadastro.put(username, newUser);
			return "sucess";
		} else {
			return "erro";
		}
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAdress() {
		return adress;
	}

	public void setAdress(String adress) {
		this.adress = adress;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}
}
